package 力扣日常刷题.木22二月.第06天212;

import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/2/12
 * @description
 */
public class Demo45贪心救生艇 {


    public int numRescueBoats(int[] people, int limit) {
        Arrays.sort(people);
        int n = people.length, l = 0;
        int ans = 0;
        for (int r = n - 1; r > l; r++) {
            if(people[r] + people[l] <= limit)l++;
            ans++;
        }
        return ans;
    }
}
